package com.cskaoyan.wordmemorize.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cskaoyan.wordmemorize.dao.entity.UserVocBoundStatisticsDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper // todo 我加的
public interface UserVocBoundStatisticsMapper extends BaseMapper<UserVocBoundStatisticsDO> {

    @Select("SELECT available FROM user_voc_bound_statistics WHERE user_id = #{userId}")
    Integer selectAvailableByUserId(@Param("userId") Long userId);

    @Update("UPDATE user_voc_bound_statistics " +
            "SET available = available - #{count}, " +
            "exchange = exchange + #{count} " +
            "WHERE user_id = #{userId} AND available >= #{count}")
    int deductAvailable(@Param("userId") Long userId, @Param("count") int count);

}
